﻿using System;
using System.Data;
using System.Collections.Generic;
using Things.Common;
using Things.Model;
using Things.DALFactory;
using Things.IDAL;
namespace Things.BLL
{
	/// <summary>
	/// CropsPlantProgress
	/// </summary>
	public partial class CropsPlantProgress
	{
		private readonly ICropsPlantProgress dal=DataAccess.CreateCropsPlantProgress();
		public CropsPlantProgress()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid PlantProgressID)
		{
			return dal.Exists(PlantProgressID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Things.Model.CropsPlantProgress model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Things.Model.CropsPlantProgress model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid PlantProgressID)
		{
			
			return dal.Delete(PlantProgressID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string PlantProgressIDlist )
		{
			return dal.DeleteList(PlantProgressIDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Things.Model.CropsPlantProgress GetModel(Guid PlantProgressID)
		{
			
			return dal.GetModel(PlantProgressID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Things.Model.CropsPlantProgress GetModelByCache(Guid PlantProgressID)
		{
			
			string CacheKey = "CropsPlantProgressModel-" + PlantProgressID;
			object objModel = Things.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(PlantProgressID);
					if (objModel != null)
					{
						int ModelCache = Things.Common.ConfigHelper.GetConfigInt("ModelCache");
						Things.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Things.Model.CropsPlantProgress)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Things.Model.CropsPlantProgress> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Things.Model.CropsPlantProgress> DataTableToList(DataTable dt)
		{
			List<Things.Model.CropsPlantProgress> modelList = new List<Things.Model.CropsPlantProgress>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Things.Model.CropsPlantProgress model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Things.Model.CropsPlantProgress();
					if(dt.Rows[n]["PlantProgressID"]!=null && dt.Rows[n]["PlantProgressID"].ToString()!="")
					{
						model.PlantProgressID=new Guid(dt.Rows[n]["PlantProgressID"].ToString());
					}
					if(dt.Rows[n]["PlantProgressName"]!=null && dt.Rows[n]["PlantProgressName"].ToString()!="")
					{
					model.PlantProgressName=dt.Rows[n]["PlantProgressName"].ToString();
					}
					if(dt.Rows[n]["PlantProgressOrder"]!=null && dt.Rows[n]["PlantProgressOrder"].ToString()!="")
					{
						model.PlantProgressOrder=int.Parse(dt.Rows[n]["PlantProgressOrder"].ToString());
					}
					if(dt.Rows[n]["IsDeleted"]!=null && dt.Rows[n]["IsDeleted"].ToString()!="")
					{
						if((dt.Rows[n]["IsDeleted"].ToString()=="1")||(dt.Rows[n]["IsDeleted"].ToString().ToLower()=="true"))
						{
						model.IsDeleted=true;
						}
						else
						{
							model.IsDeleted=false;
						}
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

